﻿using Calligraphy.CalligraphyData;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Services.Client;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Calligraphy.DataModel
{
    class BaseDataDataSource
    {
         public static  ObservableCollection<T_Author> allAuthors;

         public static  ObservableCollection<T_Style> allStyles;

         
         public async Task GetAllAuthorAndStyle()
        {
             allAuthors =
                await
                this.LoadAllAuthor();
            allStyles =
                await
                this.LoadAllStyle();
        }
        private async Task<ObservableCollection<T_Author>> LoadAllAuthor()
        {
            var searchAllAuthor =
               await
               ((DataServiceQuery<T_Author>)DataServiceContextHelper.DataContext.CreateQuery<T_Author>("SearchAllAuthor")).ExecuteAsync<T_Author>();
            allAuthors = new ObservableCollection<T_Author>();
            
            allAuthors = new ObservableCollection<T_Author>();
            foreach (var p in searchAllAuthor)
            {
                allAuthors.Add(p);
            }
            return allAuthors;
        }
        private async Task<ObservableCollection<T_Style>> LoadAllStyle()
        {
            var searchAllStyle =
                await
                ((DataServiceQuery<T_Style>)DataServiceContextHelper.DataContext.CreateQuery<T_Style>("SearchAllStyle")).ExecuteAsync<T_Style>();
            allStyles = new ObservableCollection<T_Style>();
            foreach (var p in searchAllStyle)
            {
                allStyles.Add(p);
            }
            return allStyles;
        }


        
    }
}
